Function.RegisterNamespace("xUnit.js.Console.Output");

xUnit.js.Console.Output.OutputFormatter=function(){
    // Private Members
    var _candidate;
    var _level;
    var _levels=xUnit.js.Console.Output.OutputFormatter.OutputLevels;
    var _strategyManager;
    var _types=xUnit.js.Console.Output.OutputFormatter.OutputTypes;

    // Public Members
    this.OutputLevel;
    this.OutputLevels;
    this.OutputTypes;
    this.Strategies;

    // ctor
    function OutputFormatter(){
        _candidate=_types.text;
        _level=_levels.compact;
        this.OutputLevels=_levels;
        this.OutputTypes=_types;
        this.Strategies=_strategyManager=new System.Script.Strategy.StrategyManager();
        if(xUnit.js.Console.Output.OutputStrategy){
            _strategyManager.Add(xUnit.js.Console.Output.OutputStrategy.Json);
            _strategyManager.Add(xUnit.js.Console.Output.OutputStrategy.Text);
            _strategyManager.Add(xUnit.js.Console.Output.OutputStrategy.Xml);
        };
    }
    OutputFormatter.apply(this,arguments);

    // Public Methods
    this.SetLevel=function(level){
        if(Object.IsType(Function,level&&level.toString)){
            level=level.toString().toLowerCase();
            if(_levels[level])_level=_levels[level];
        }
    };

    this.SetType=function(type){
        if(Object.IsType(Function,type&&type.toString)){
            type=type.toString().toLowerCase();
            if(_types[type])_candidate=_types[type];
        }
    };
    
    // IOutputStrategy Members
    this.Prologue=function(){
        return getOutputStrategy().Prologue();
    };

    this.Epilogue=function(){
        return getOutputStrategy().Epilogue();
    };
    
    this.BeginFileLoad=function(){
        return getOutputStrategy().BeginFileLoad();
    };

    this.FileLoadSuccess=function(file,duration){
        return getOutputStrategy().FileLoadSuccess(file,duration);
    };

    this.CompleteFileLoad=function(files,duration){
        return getOutputStrategy().CompleteFileLoad(files,duration);
    };
    
    this.BeginRun=function(){
        return getOutputStrategy().BeginRun();
    };

    this.CompleteRun=function(successes,failures,errors,warnings,skipped,duration){
        return getOutputStrategy().CompleteRun(successes,failures,errors,warnings,skipped,duration);
    };

    this.BeginComponent=function(component){
        return getOutputStrategy().BeginComponent(component);
    };

    this.CompleteComponent=function(component,duration){
        return getOutputStrategy().CompleteComponent(component,duration);
    };

    this.Enumerate=function(component){
        return getOutputStrategy().Enumerate(component);
    };

    this.Error=function(error){
        return getOutputStrategy().Error(error);
    };

    // Private Methods
    function getOutputStrategy(){
        return _strategyManager.Get(_candidate,false,{OutputLevel:_level});
    }

};

xUnit.js.Console.Output.OutputFormatter.OutputLevels={
    compact:"compact",
    verbose:"verbose"
}

xUnit.js.Console.Output.OutputFormatter.OutputTypes={
    json:"json",
    text:"text",
    xml:"xml"
};

xUnit.js.Console.Output.OutputFormatter.Implement(xUnit.js.Console.Output.IOutputStrategy,'xUnit.js.Console.Output.OutputFormatter');